package com.rs.game.player.dialogues;

import java.util.TimerTask;

import com.rs.cores.CoresManager;

public class ArmadylBstaff extends Dialogue {

	int npcId;
	
	private boolean timerDone;
	
	private void settimerDone(boolean timerDone) {
		this.timerDone = timerDone;
	}
	
	private void startTimer() {
		CoresManager.fastExecutor.schedule(new TimerTask() {
			int timer = 20; //The timer counts down from whatever you set it to - it is currently set at 2 minutes.
			@Override
			public void run() {
			if (timer == 0) {
				player.getPackets().sendGameMessage("<col=ff0000>Your armadyl battlestaff is finished! Get it at Tool Leprechaun!");
				settimerDone(true);
				end();
			}
			if (timer > 0) {
			timer--;
				}
			}
		}, 0L, 1000L);
	}
	
	@Override 
	public void start() {
		npcId = (int) parameters[0];
		sendNPCDialogue(npcId, Expressions.HAPPY_TALKING, "Heya Matey! How can I help you?");

	}
	
	@Override
	public void run(int interfaceId, int componentId) {
		switch (stage) {
		case -1:
			stage = 0;
			sendOptionsDialogue("How can I help you?", "I want to make an Armadyl battlestaff.", "I want to claim my armadyl battlestaff.", "Nevermind.");
			break;
		case 0:
				switch (componentId) {
				case OPTION_1:
					stage = 1;	
					sendNPCDialogue(npcId, Expressions.HAPPY_TALKING, "I only charge 5M coins! So, what will it be?");
					break;
				case OPTION_2:
					if (timerDone) {
						//sendNPCDialogue(npcId, Expressions.HAPPY_TALKING, "Heya Matey! Good news, I finished your armadyl battlestaff! Here you go!");
						if (player.getInventory().hasFreeSlots()) {
							player.getInventory().addItem(21777, 1);
							settimerDone(false);
							break;
						} else {
							player.getBank().addItem(21777, 1, true);
							player.getPackets().sendGameMessage("Your armadyl battlestaff is added to your bank.");
							settimerDone(false);
							break;
						}
					} else if (!timerDone) {
						sendNPCDialogue(npcId, Expressions.ANGRY, "Almost done, come back later.");
						end();
						break;
					}
				case OPTION_3:
					end();
					break;
				}
			break;
		case 1:
			stage = 2;
			sendOptionsDialogue("What will it be?", "Okay!", "No thanks");
			break;
		case 2:
			switch (componentId) {
			case OPTION_1:
				if (player.getInventory().containsItem(21775, 1) && player.getInventory().containsItem(1391, 1) && player.getInventory().containsItem(995, 5000000)) {
					startTimer();
					player.getInventory().deleteItem(21775, 1);
					player.getInventory().deleteItem(1391, 1);
					player.getInventory().deleteItem(995, 5000000);
					player.getPackets().sendGameMessage("Your armadyl battlestaff will be finished in 5 hours.");
					end();
				} else {
					player.getPackets().sendGameMessage("You need an orb of armadyl, a battlestaff and 5M coins in order to make an armadyl battlestaff.");
					end();
				}
			case OPTION_2:
				end();
				break;
			}
			break;
			}
		}


	@Override
	public void finish() {
		// TODO Auto-generated method stub
		
	}

}
